package com.tangfuzhong.type;

import com.tangfuzhong.bean.Car;
import com.tangfuzhong.bean.Person;
import com.tangfuzhong.bean.Person2;

import java.util.ArrayList;
import java.util.List;

/**
 * <p><em>Created on 2024/11/28 14:11</em></p>
 * 泛型学习
 * @author fuzhongtang
 * @since 1.0.1
 */
public class MyArrayList<T> {
    List<T> list = new ArrayList<T>();

    int size = 0;

    public boolean add(T t){
        list.add(size,t);
        size++;
        return true;
    }

    public T get(int index){
        return (T)list.get(index);
    }

    public static void main(String[] args) {
        MyArrayList<String> myArrayList = new MyArrayList<>();
        myArrayList.add("tang");
        System.out.println(myArrayList.get(0));

        MyArrayList<Person> myArrayList2 = new MyArrayList<>();
        myArrayList2.add(new Person("lili",23));
        myArrayList2.add(new Person2("lili2",23));
        System.out.println(myArrayList2.get(1).toString());
    }
}
